<?php 
use_helper('format');
use_helper('pagination');
$iconsSize = sfConfig::get('app_defaultViewer_iconssize', '16');
if(is_null($hide))
	$hide = array();
?>
<?php if(isset($pager)):?>
<div id="pag_nav_haut">
	<?php echo Util::pager_navigation($pager, $orderByCol);?>
</div>

<?php endif;?>
<div class="showTable">
<?php if($addFieldSet):?>
	<fieldset><legend><?php echo __('List of '). __($objDef->labelPlural,null,'forms') ?></legend>
 <?php endif;?>
 <?php if($addCreate){
   			if($ajaxActions){?>
   			<a class="fancy" href="<?php echo url_for($module . '/newAjax?fancy=true&className='.$objDef->className . '&fieldName=' . $ownerFieldName . "&id=new");?>"><img src="/images/icons/<?php echo $iconsSize?>/add.png" title="<?php echo __('Create New') . ' ' . $objDef->label ?>"></a>
<?php    	}else{?>
				<?php echo link_to('<img src="/images/icons/'.$iconsSize.'/add.png" title="'. __('Create New').'"'. $objDef->label.'/>', $module.'/new?className='.$objDef->className);?>
<?php    	}
   		}
?>
<?php if($addExports and !$ajaxActions){
	   			$exportFormat = sfConfig::get('app_defaultViewer_exportFormat', 'csv');
	   			echo link_to('<img src="/images/icons/'.$iconsSize.'/export.png"  style="margin-left:5px;" title="'. __('Export ').'"'. $objDef->label.'/>', $module.'/export?className='.$objDef->className.'&format='.$exportFormat . $exportParams);
   		}
   ?>
<div id="list_'. $objDef->className.'"></div>
<table class="<?php echo $tableClass?>">
<?php //echo $objDef->renderListHeader($hide,'table',$addActions, 0, $addOrderLink, $orderFunctionParams);

		$width = 0;
		$style = 'table';
		$html = '';
		$html .= '<thead class="list_header" ><tr>';
		if($addActions){
			$html .= '<th>'.__('Actions').'</th>';
		}
   		if($orderField != ''){
	   		$orderColArray=explode('*',$orderField);
	   	}
   		foreach($objDef->attributes as $fieldName => $att){
	   		if($att['list'] and !in_array($fieldName, $hide) and $att['type'] != 'List'){
	   			if($style == 'table'){
	   				//$html .= '<th width="100px" class="table_header">';
	   				$html .= '<th>';
	   			}
	   			$html .= $objDef->renderLabel($fieldName);
	   			if($orderField != ''){
	   				if($orderColArray[0]==$fieldName){
	   					if($orderColArray[1]=='desc'){
	   						$icon = 'arrow-down.gif';
	   					}else{
	   						$icon = 'arrow-up.gif';
	   					}
	   					$html .= '&nbsp;<img src="/images/icons/'.$icon.'"/>';
	   				};
	   			}
	   			
	   			if($addOrderLink and $att['type'] <> 'function' and $att['type'] <> 'List'){
	   				if($orderFunctionParams != ''){
	   					$comma = ',';
	   				}else{
	   					$comma = '';
	   				}
	   				$html .= '<br /><a href="javascript:refresh('.$orderFunctionParams.$comma.'\''.$fieldName.'*asc\');"><img src="/images/icons/16/sort_asc.png" title="'.__('Sort A to Z').'"/></a>'; 
	   				$html .= '&nbsp;&nbsp;<a href="javascript:refresh('.$orderFunctionParams.$comma.'\''.$fieldName.'*desc\')"><img src="/images/icons/16/sort_desc.png" title="'.__('Sort Z to A').'"/></a>';
	   			}
	   			if($style == 'table'){
	   				$html .= '</th>';	
	   			}
	   			if($fieldName=='forme_juridique' and $vue=='allcustomers'){
	   				$html .= '<th>';
	   				$html .= __('Commercial');
	   				$html .= '</th>';
	   			}
	   		}
   		}
   		$html .= '</tr></thead>';
   		echo $html;
?>
<tbody class="list_elem">
<?php 
		if(is_array($items)){
			$keys=array_keys($items);
		}
		$i=0;
		$key=0;
		foreach($items as $item):?>
			<tr>
			<?php if($addActions):?>
				<?php if($ajaxActions):?>
					<?php if(isset($keys)) $key=$keys[$i];?>
					<td>
					<a class="fancy" href="<?php echo url_for($module . '/newAjax?fancy=true&className='.$objDef->className . '&fieldName=' . $ownerFieldName . '&id=' . $key);?>"><img src="/images/icons/<?php echo $iconsSize?>/edit.png" title="<?php echo __('Edit')?>"></a>
					<a href="javascript:deleteItem('<?php echo $ownerFieldName.'Form'?>','<?php echo $objDef->className ?>','<?php echo $ownerFieldName?>','<?php echo $key ?>');"><img title = "<?php echo __('Delete')?>" src="/images/icons/<?php echo $iconsSize?>/delete.png"/></a>
					
					</td>
	   			<?php else:?>
					<td><?php
					echo link_to('<img title = "'. __('Show').'" src="/images/icons/'.$iconsSize.'/show.png"/>', $module. '/show?id='.$item['id'].'&className='.$objDef->className);
					if(!$objDef->isReadOnly) 
						echo link_to('<img title = "'. __('Edit').'" src="/images/icons/'.$iconsSize.'/edit.png"/>', $module.'/edit?id='.$item['id'].'&className='.$objDef->className);
					if($objDef->canBeDeleted) 
						echo link_to('<img title = "'. __('Delete').'" src="/images/icons/'.$iconsSize.'/delete.png"/>', $module.'/delete?id='.$item['id'].'&className='.$objDef->className, array('method' => 'delete', 'confirm' =>  __('Are you sure')));
					?></td>
	   			<?php endif;?>
			<?php endif;?>
			<?php 
				$html = '';
				foreach($objDef->attributes as $fieldName => $att){
			   		if($att['list'] and !in_array($fieldName, $hide) and $att['type'] != 'List'){
						if($style == 'table'){
				   				$html .= '<td>';
				   		}
				   		$html .= $objDef->renderAttributeValue($item, $fieldName);
				   		if($style == 'table'){
				   				$html .= '</td>';
				   		}
				   		if($fieldName=='forme_juridique'and $vue=='allcustomers'){
			   				$html .= '<td>';
			   				$html .= $item['commercial']['initiales'];
			   				$html .= '</td>';
	   					}
				   		
			   		}
				}
				echo $html;?>
			</tr>
			<?php $i++;?>
		<?php endforeach;?>
		<input type="hidden" id="q_list_<?php echo $objDef->className?>" value="<?php echo $i ?>">
		 </tbody></table>
		<?php if($addFieldSet):?>
			 </fieldset>
		<?php endif;?>
		 </div>

<script type="text/javascript">
<!--

//-->


</script>